
package com.liao.badminton.controller;

import com.liao.badminton.code.*;
import com.liao.badminton.dto.FileShardDto;
import com.liao.badminton.service.FileShardService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import com.liao.badminton.code.validation.Delete;
import com.liao.badminton.code.validation.Insert;
import com.liao.badminton.code.validation.Update;
import com.liao.badminton.code.validation.FindDetail;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile;

/**
* @author liaocheng
* @date 2024-11-01
* description:文件
*/
@RestController
@RequestMapping(value = "/fileShard")
// @PreAuthorize("@ss.hasPermission('fileShard')")//权限管理;
public class FileShardController {

  //  private static  Logger logger= LoggerFactory.getLogger(FileShardController.class);

    @Autowired
    private FileShardService fileShardService;




    /**
    * 新增fileShard
    */
    @RequestMapping(value = "/add")
    @PreAuthorize("@ss.hasPermission('fileShard:add')")//权限管理;
    public ResponseRest<Long> add(@RequestBody @Validated(Insert.class) FileShardDto fileShard)throws ProjectException{
        return fileShardService.saveFileShard(fileShard);
    }
    /**
    * 批量删除
    */
    @RequestMapping(value = "/deletes")
    @PreAuthorize("@ss.hasPermission('fileShard:deletes')")//权限管理;
    public ResponseRest<Boolean> deletes(@RequestBody @Validated(Delete.class) FileShardDto param)throws ProjectException{
        return fileShardService.deletesFileShard(param);
    }
    /**
    * 修改fileShard
    */
    @RequestMapping(value = "/update")
    @PreAuthorize("@ss.hasPermission('fileShard:update')")//权限管理;
    public ResponseRest<Boolean> update(@RequestBody @Validated(Update.class) FileShardDto param)throws ProjectException{
        return fileShardService.updateFileShard(param);
    }

    @RequestMapping(value = "/findDetail")
    @PreAuthorize("@ss.hasPermission('FileShard:findDetail')")//权限管理;
    public ResponseRest findDetail(@RequestBody @Validated(FindDetail.class) FileShardDto param) throws ProjectException {
      return fileShardService.findDetail(param);
    }
    /**
    * 分页查询列表
    */
    @RequestMapping(value = "/list")
    @PreAuthorize("@ss.hasPermission('fileShard:list')")//权限管理;
    public ResponseRest list(@RequestBody PageParam<FileShardDto> body) throws ProjectException{
      return   fileShardService.findFileShardByPageParam(body);
    }
    @RequestMapping(value = "/test")
    public ResponseRest list() {
        return ResponseRest.suc("test", "test");
    }


    @RequestMapping("uploadFileShard")
    public ResponseRest uploadFileShard(@RequestParam MultipartFile shard, FileShardDto fileShard) {
        return fileShardService.uploadFileShard(shard, fileShard);
    }

    @RequestMapping("bs64Upload")
    public ResponseRest bs64Upload(FileShardDto fileShard) {
        return fileShardService.bs64Upload(fileShard);
    }

}
